<script type="text/javascript">
	fields_no_of_distances = '<?php echo $selected_cities_count; ?>';
    var max_no_of_distances = 10;
    function addCityDistance() {
      if (fields_no_of_distances < max_no_of_distances) {
        var id = "file" + fields_no_of_distances;
        var cities_list = $('#city').html();
        var text_to_be_appended = '<select style="min-width:150px;" name="cbo_cities[]" >'+cities_list+'</select>';
        text_to_be_appended+='&nbsp;<input type="text" name="distance[]" style="width:50px; " />';
        text_to_be_appended+='&nbsp;<a href="javascript:void(0); " onclick="removeCityDistance(this.parentNode)" >remove</a>';

        $('#distance_text').append( '<div style="padding:5px 0px; ">'+text_to_be_appended+'</div>');
        fields_no_of_distances += 1;
      } else {
        document.getElementById('distance_warning').innerHTML =
          "Max "+max_no_of_distances+" city distance allowed.";
        document.form.add.disabled = true;
      }
    }

    function removeAddedCityDistance(id){
    	document.getElementById('city_distance_'+id).innerHTML = "";
    	fields_no_of_distances -= 1;
    }

    function removeCityDistance( el ) {
    	if (fields_no_of_distances > 0) {
	        document.getElementById('distance_warning').innerHTML = "";
        	var parent = document.getElementById('distance_text');
        	parent.removeChild(el);
        	fields_no_of_distances -= 1;
      	}
    }

	fields = 0;
	var max_venue_images = 20;
	function addInput() {
	  if (fields < max_venue_images) {
		var id = "file" + fields;
		$('#text').append( "<div style='padding:5px 0px; '><input type='file' name='venue_images[]' />&nbsp;<input type='text' name='image_title[]' placeholder='Image Title' />&nbsp;<input type='text' name='image_tooltip[]' placeholder='Image Tooltip' />&nbsp;<input type='text' name='image_description[]' placeholder='Image Description' />" +
		  " <a href='javascript:void(0); ' onclick='removeInput(this.parentNode)' >remove</a></div>");

		fields += 1;
	  } else {
		document.getElementById('warning').innerHTML =
		  "Only "+max_venue_images+" upload fields allowed.";
		document.form.add.disabled = true;
	  }
	}

	function removeInput( el ) {
	  if (fields > 0) {
		document.getElementById('warning').innerHTML = "";
		var parent = document.getElementById('text');
		parent.removeChild(el);
		fields -= 1;
	  }
	}
	
	$(document).ready(function(){
		var root_path = '<?php echo _SITE_ADMIN_URL_?>';
		$('#country').change(function(){
			var country = $(this).val();
			path = root_path+'ajax/getGeo.php?id='+country+'&type=state';
			$.ajax({url: path,	
				success: function(response) {
					$('#state').html(response);
				}
			});
			
		});
		$('#state').change(function(){
			var country = $(this).val();
			path = root_path+'ajax/getGeo.php?id='+country+'&type=city';
			$.ajax({url: path,	
				success: function(response) {
					$('#city').html(response);
				}
			});
			
		});
	});
</script>
<div class="container_12"> 
	<div class="module">
		<h2><span><?=$_title?></span></h2>
		<div class="module-body">
			<form id="adminForm" name="admin_frm" method="post" enctype="multipart/form-data">
				<div style="margin-top:13px;">
					<?php
						if(isset($errMsg)){?>
							<span class="notification"><?php echo $_MESSESGE[$errMsg];?></span>
					<?php }?>
				</div>
				<div></div>
				<p>
					<label>Vendor</label>
					<select class="input-short" id="vendor_id" name="vendor_id">
						<option value="">Select Vendor</option>
						<?php
						foreach($vendors as $key => $val){
							$selected = ($val['id'] == $result['vendor_id'])?'selected':''; ?>
							<option value="<?php echo $val['id']; ?>" <?php echo $selected; ?>><?php echo $val['name']; ?></option>
						<?php } ?>
					</select>
				</p>
				<!--
				<p>
          			<label>Vendor Services</label>
          			<select class="input-short" name="vendor_services[]" id="vendor_services" multiple>
              			<?php echo $vendor_services; ?>
          			</select>
        		</p> -->
				<p>
					<label>Venue Name</label>
					<div id="availability_info"></div>
					<input type="text" class="input-short check_availability" id="venue_name" name="venue_name" value="<?php echo $result['venue_name']; ?>"/>
				</p>
				<p>
					<label>Display Name</label>
					<input type="text" class="input-short" id="display_name" name="display_name" value="<?php echo $result['display_name']; ?>"/>
				</p>
				<p>
					<label>Description</label>
					<?php $editor->editor('venue_description', $result['venue_description']) ;?>
				</p>
				<p>
					<label>Min Capacity</label>
					<input type="text" class="input-short" id="min_capacity" name="min_capacity" value="<?php echo $result['min_capacity']; ?>"/>
				</p>
				<p>
					<label>Max Capacity</label>
					<input type="text" class="input-short" id="max_capacity" name="max_capacity" value="<?php echo $result['max_capacity']; ?>"/>
				</p>
				<p>
					<label>Available Seating</label>
					<input type="text" class="input-short" id="available_seating" name="available_seating" value="<?php echo $result['available_seating']; ?>"/>
				</p>
				<p>
					<label>Address</label>
					<textarea rows="7" cols="90" class="input-short" id="address" name="address"><?php echo $result['address']; ?></textarea>
				</p>
				<p>
					<label>Country</label>
					<select class="input-short" id="country" name="country">
						<?php echo $dropdown_countries; ?>
					</select>
				</p>
				<p>
					<label>State</label>
					<select class="input-short" id="state" name="state">
						<?php echo $dropdown_states; ?>
					</select>
				</p>
				<p>
					<label>City</label>
					<select class="input-short" id="city" name="city">
						<?php echo $dropdown_cities; ?>
					</select>
				</p>
				<p>
					<label>Similar Venues</label>
					<select class="input-short" id="similar_venues" name="similar_venues[]" multiple>
						<!--<option value="veg">Select Similar Venues</option>
						<?php
						foreach($venues as $key => $val){?>
							<option value="<?php echo $val['id']; ?>"><?php echo $val['venue_name']; ?></option>
						<?php } ?>-->
					</select>
				</p>
				<p>
		            <label>City Distances : </label>
		            <?php
		            	if(!empty($venue_distances)){
		            		$str = '';
		            		foreach($venue_distances as $key => $val){
		            			$str.='<p id="city_distance_'.$val['city_id'].'">';
		            			$str.='<select style="min-width:150px;" name="cbo_cities[]">';
		            			foreach($selected_cities as $inner_key => $inner_val){
		            				$selected = ($val['city_id'] == $inner_val['id'])?'selected':'';
		            				$str.='<option value="'.$inner_val['id'].'" '.$selected.'>'.$inner_val['name'].'</option>';
		            			}
		            			$str.='</select>';
		            			$str.='&nbsp; <input type="text" name="distance[]" style="width:50px; " value="'.$val['distance'].'"/>';
		            			$str.='&nbsp;<a href="javascript:void(0); " onclick="removeAddedCityDistance('.$val['city_id'].')" >remove</a>';
		            			$str.='</p>';
		                	}
		                }else{
			                $str.="No city distance Provided.";
			            }
			            echo $str;
		            ?>
		            

		            <div id="distance_text"></div>
                    <div id="distance_warning"></div>
                    <input type="button" value="Add City Distance" onclick="addCityDistance(); ">
                </p>
				<p>
					<label>Landmark</label>
					<input type="text" class="input-short" id="landmark" name="landmark" value="<?php echo $result['landmark']; ?>"/>
				</p>
				<p>
					<label>Contact Person</label>
					<textarea rows="7" cols="90" class="input-short" id="contact_person" name="contact_person"><?php echo $result['contact_person']; ?></textarea>
				</p>
				<p>
					<label>Booking Mode</label>
					<select class="input-short" id="booking_mode" name="booking_mode">
						<option value="">Select Booking Mode</option>
							<?php
							foreach($booking_mode as $key => $val){
								$selected =($key == $result['booking_mode'])?'selected':''; ?>
								<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $val; ?></option>
							<?php } ?>
					</select>
				</p>
				<p>
					<label>Parking</label>
					<input type="radio" name="parking" value="1" <?php echo $checked = ($result['parking'] == 1)?'checked':''; ?> /> Yes
					<input type="radio" name="parking" value="0" <?php echo $checked = ($result['parking'] == 0)?'checked':''; ?> /> No
				</p>
				<p>
					<label>Venue Type</label>
					<select class="input-short" id="venue_type" name="venue_type">
						<option value="">Select Venue Type</option>
						<?php
						foreach($venue_type as $key => $val){
							$selected =($val['id'] == $result['venue_type'])?'selected':'';?>
							<option value="<?php echo $val['id']; ?>" <?php echo $selected; ?>><?php echo $val['venue_type']; ?></option>
						<?php } ?>
					</select>
				</p>
				<p>
					<label>Cutoff Days</label>
					<input type="text" class="input-short" id="cutoff_days" name="cutoff_days" value="<?php echo $result['cutoff_days']; ?>"/>
				</p>
				<p>
					<label>Tags</label>
					<input type="text" class="input-short" id="tags" name="tags" value="<?php echo $result['tags']; ?>"/>
				</p>
				<p>
					<label>Food Type</label>
					<select class="input-short" id="food_type" name="food_type">
						<option value="">Select Food Type</option>
						<?php
						foreach($food_type as $key => $val){
							$selected = ($key == $result['food_type'])?'selected':''?>
							<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $val; ?></option>
						<?php } ?>
					</select>
				</p>
				<p>
					<label>Zone</label>
					<select class="input-short" id="zone" name="zone">
						<?php echo $dropdown_zones; ?>
					</select>
				</p>
				<p>
					<label>Mobile Number</label>
					<input type="text" class="input-short" id="mobile_no" name="mobile_no" value="<?php echo $result['mobile_no']; ?>"/>
				</p>
				<p>
					<label>Landline Phone 1</label>
					<input type="text" class="input-short" id="landline_phone1" name="landline_phone1" value="<?php echo $result['landline_phone1']; ?>"/>
				</p>
				<p>
					<label>Landline Phone 2</label>
					<input type="text" class="input-short" id="landline_phone2" name="landline_phone2" value="<?php echo $result['landline_phone2']; ?>"/>
				</p>
				<p>
					<label>Latitude</label>
					<input type="text" class="input-short" id="latitude" name="latitude" value="<?php echo $result['latitude']; ?>"/>
				</p>
				<p>
					<label>Longitude</label>
					<input type="text" class="input-short" id="longitude" name="longitude" value="<?php echo $result['longitude']; ?>"/>
				</p>
				<p>
					<label>Booking Amount</label>
					<input type="text" class="input-short" id="booking_amount" name="booking_amount" value="<?php echo $result['booking_amount']; ?>"/>
				</p>
				<p>
					<label>Cancellation Policy</label>
					<textarea rows="7" cols="90" class="input-short" id="cancellation_policy" name="cancellation_policy"><?php echo $result['cancellation_policy']; ?></textarea>
				</p>
				<p>
					<label>Terms & Conditions</label>
					<textarea rows="7" cols="90" class="input-short" id="tc_policy" name="tc_policy"><?php echo $result['tc_policy']; ?></textarea><br/><br/>
					<input type="checkbox" name="termsandconditions" id="termsandconditions" value=1 checked /> I agree with terms and conditions.
				</p>

				<p>
	                <label>Venue Image</label>
	                <input type="file" name="venue_image" id="venue_image" readonly /><br/>
	                Thumb Preview : <img src="../../shaadi-images/venue_images/thumb/<?php echo $result['venue_image']; ?>" /><br/>
	                <!-- Small Preview : <img src="../../shaadi-images/wedding-package/small/<?php echo $result['venue_image']; ?>" /><br/>
	                Big Preview : <img src="../../shaadi-images/wedding-package/big/<?php echo $result['venue_image']; ?>" /> -->
	            </p> 
           

				<p>
                <label>Venue Gallery Images</label>
                <div>
                    <table border="0" cellspacing="0" cellpadding="0" style="border:0px; " >
                        <tr>
                            <?php
                            if(!empty($venue_images)){
                                foreach($venue_images as $key => $val){?>
                                   
                                    <td style="border:0px; ">
                                        <img src="../../shaadi-images/venue_images/thumb/<?php echo $val['image']; ?>" title="<?php echo $val['image_tooltip']; ?>" />&nbsp;<br/>Title : <?php echo $val['image_title']; ?> &nbsp;<br/>Description : <?php echo $val['image_description']; ?>
                                    </td>
                                    
                                <?php }
                            }else{
                                echo "<td>No Venue image available.</td>";
                            }?>
                        </tr>
                    </table>
                
					<div id="text"></div>
					<div id="warning"></div>
					<input type="button" name="addImages" value="Add Images" onclick="addInput(); ">
				</p>

				<fieldset>
					<input type="hidden" class="input-short" id="id" name="id" value="<?php echo $result['id']; ?>"/>
					<input class="submit-green" type="submit" value="Submit" name="submit"/> 
					<input class="submit-gray" type="reset" value="Cancel" />
				</fieldset>
			</form>
        </div> <!-- End .module-body -->
    </div>  <!-- End .module -->
	<div style="clear:both;"></div>
</div>
<script type="text/javascript">
	var root_path = '<?php echo _SITE_ADMIN_URL_?>';
	var table = 'venues';
	var field = 'venue_name';
	
	jQuery.validator.addMethod(
		"selectVendorNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a vendor."
	);
	
	jQuery.validator.addMethod(
		"selectCountryNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a country."
	);
	
	jQuery.validator.addMethod(
		"selectStateNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a state."
	);
	
	jQuery.validator.addMethod(
		"selectCityNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a city."
	);
	
	jQuery.validator.addMethod(
		"selectBookingModeNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a booking mode."
	);
	
	jQuery.validator.addMethod(
		"selectVenueTypeNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a venue type."
	);
	
	jQuery.validator.addMethod(
		"selectVenueServicesNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select venue services."
	);
	
	jQuery.validator.addMethod(
		"selectFoodTypeNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a food type."
	);
	
	jQuery.validator.addMethod(
		"selectZoneNone",
		function(value, element) {
			if (element.value == ""){
				return false;
			}
			else return true;
		},
		"Please select a zone."
	);
	
	$().ready(function() {

		$('#city').change(function(){
	      	var city = $(this).val();
			path = root_path+'ajax/getGeo.php?id='+city+'&type=similar_venues';
	      	$.ajax({url: path,  
	        	success: function(response) {
		        	$('#similar_venues').html(response);
	      		}
	      	});
	    });

		$("#adminForm").validate({
			rules: {
				vendor_id: {
					selectVendorNone: true
				},
				venue_name: "required",
				display_name: "required",
				venue_description: "required",
				min_capacity: {
					required: true,
					digits: true
				},
				max_capacity: {
					required: true,
					digits: true
				},
				available_seating: {
					required: true,
					digits: true
				},
				address: "required",
				country: {
					selectCountryNone: true
				},
				state: {
					selectStateNone: true
				},
				city: {
					selectCityNone: true
				},
				landmark: "required",
				contact_person: "required",
				booking_mode: {
					selectBookingModeNone: true
				},
				inclusion: "required",
				exclusion: "required",
				venue_type: {
					selectVenueTypeNone: true
				},
				"venue_services[]": {
					selectVenueServicesNone: true
				},
				cutoff_days: "required",
				tags: "required",
				food_type: {
					selectFoodTypeNone: true
				},
				zone: {
					selectZoneNone: true
				},
				mobile_no: {
					required: true
				},
				booking_amount: {
					required: true,
					digits: true
				},
				termsandconditions: "required"
			},

			messages: {
				venue_name: "Please enter venue name",
				display_name: "Please enter venue display name",
				venue_description: "Please enter venue description name",
				address: "Please enter venue address",
				landmark: "Please enter venue landmark",
				contact_person: "Please enter venue contact person",
				cutoff_days: "Please enter cutoff days",
				tags: "Please enter venue tags",
				mobile_no: "Please enter mobile number",
				booking_amount: "Please enter digits only",
				termsandconditions: "Please accept terms & conditions"
			}
		});
	});
</script> 
<script type="text/javascript" src="<?php echo _ADMIN_JS_; ?>check_availability.js"></script>